<template>
  <div class="school-events">
    <section class="common-bar search-bar clear">
      <template>
        <el-radio-group class="fl" v-model="select_type" @change="getList">
          <el-radio v-for="(item,index) of selectOption" :key="index" :label="item.value">{{item.label}}</el-radio>
        </el-radio-group>
      </template>
      <router-link to="/events/initiate">
        <el-button type="warning" round class="initiate-btn fr">发起活动</el-button>
      </router-link>
    </section>
    <section class="common-cards activities-container">
      <div class="search-bar clear">
        <template>
          <el-radio-group class="fl" v-model="order" @change="getList">
            <el-radio v-for="(item,index) of orderOption" :key="index" :label="item.value">{{item.label}}<i class="el-icon-sort-down"></i></el-radio>
          </el-radio-group>
        </template>
        <div class="select-tools fr">
          <template>
            <el-select v-model="level_type" placeholder="请选择活动" @change="getList">
              <el-option v-for="item in levelOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </template>
          <template>
            <el-select v-model="status" placeholder="请选择状态" @change="getList">
              <el-option v-for="item in allStatusOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </template>
        </div>
      </div>
      <div class="activities-content clear">
        <!-- 全部活动 -->
        <template v-if="select_type=='-1'">
          <el-col :span="8" v-for="(item,index) of listData" :key="index">
            <div class="activitie-item">
              <i :class="'Status'+item.show_status_int">{{item.show_status_text}}</i>
              <div class="activitie-poster">
                <router-link :to="{path: '/events/activitiesDetails', query: {id: item.id}}">
                  <img v-if="item.picture==''" src="../../../assets/images/events/bg-img.png">
                  <img v-else :src="BASE_URL+item.picture" :onerror="errorImg">
                </router-link>
              </div>
              <div class="activitie-info">
                <router-link :to="{path: '/events/activitiesDetails', query: {id: item.id}}">
                  <p class="activitie-title">{{item.name}}</p>
                </router-link>
                <p class="start-time">{{item.start_time}}</p>
                <p class="place-info"><i class="place-icon"></i><i>{{item.place}}</i></p>
              </div>
            </div>
          </el-col>
        </template>
        <!-- 我参与的 -->
        <template v-if="select_type=='1'">
          <el-col :span="8" v-for="(item,index) of listData" :key="index">
            <!-- 仅显示在线报名的 -->
            <div class="activitie-item" v-if="item.online=='1'">
              <i :class="'aStatus'+item.show_status_int">{{item.show_status_text}}</i>
              <div class="activitie-poster">
                <router-link :to="{path: '/events/activitiesDetails', query: {id: item.id}}">
                  <img v-if="item.picture==''" src="../../../assets/images/events/bg-img.png">
                  <img v-else :src="BASE_URL+item.picture" :onerror="errorImg">
                </router-link>
              </div>
              <div class="activitie-info">
                <router-link :to="{path: '/events/activitiesDetails', query: {id: item.id}}">
                  <p class="activitie-title">{{item.name}}</p>
                </router-link>
                <p class="start-time">{{item.start_time}}</p>
                <p class="place-info"><i class="place-icon"></i><i>{{item.place}}</i></p>
              </div>
              <div class="review-status">
                <span :class="'rStatus'+item.show_status_int"><i></i><i>{{item.show_status_text}}</i></span>
                <i class="del-btn el-icon-delete fr" @click="delActivity(item)"></i>
                <i class="edit-btn el-icon-edit fr" v-if="item.show_status_int=='1'" @click="editActivity(item)"></i>
              </div>
            </div>
          </el-col>
        </template>
        <!-- 我发起的 -->
        <template v-if="select_type=='2'">
          <el-col :span="8" v-for="(item,index) of listData" :key="index">
            <div class="activitie-item">
              <div class="activitie-poster">
                <router-link :to="{path: '/events/activitiesDetails', query: {id: item.id}}">
                  <img v-if="item.picture==''" src="../../../assets/images/events/bg-img.png">
                  <img v-else :src="BASE_URL+item.picture" :onerror="errorImg">
                </router-link>
              </div>
              <div class="activitie-info">
                <router-link :to="{path: '/events/activitiesDetails', query: {id: item.id}}">
                  <p class="activitie-title">{{item.name}}</p>
                </router-link>
                <p class="start-time">{{item.start_time}}</p>
                <p class="place-info"><i class="place-icon"></i><i>{{item.place}}</i></p>
              </div>
              <div class="review-status">
                <span :class="'rStatus'+item.show_status_int"><i></i><i>{{item.show_status_text}}</i></span>
                <i class="del-btn el-icon-delete fr" @click="delActivity(item)"></i>
                <i class="edit-btn el-icon-edit fr" v-if="item.show_status_int=='1'" @click="editActivity(item)"></i>
              </div>
            </div>
          </el-col>
        </template>
        <template v-if="listData.length==0">
          <div v-if="select_type=='-1'||select_type=='2'" class="no-data-tips tips1"></div>
          <div v-if="select_type=='1'" class="no-data-tips tips2"></div>
        </template>
      </div>
      <div class="pageBox">
        <el-pagination v-if="total_number > page_size" @current-change="change_page" :page-size="page_size" :current-page="page_index" layout="prev, pager, next" :total="total_number">
        </el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userId: this.$g.user_id,
      select_type: "-1",//活动状态
      selectOption: [
        {
          value: "-1",
          label: "全部活动"
        },
        {
          value: "1",
          label: "我参与的"
        },
        {
          value: "2",
          label: "我发起的"
        },
      ],
      order: "time",//分类
      orderOption: [
        {
          value: "time",
          label: "时间"
        },
        {
          value: "count",
          label: "人数"
        },
        {
          value: "comment",
          label: "讨论"
        },
      ],
      errorImg:
        'this.src="' +
        require("../../../assets/images/events/bg-img.png") +
        '"',
      listData: [],//活动数据
      //全部活动select
      levelOptions: [
        {
          value: "-1",
          label: '全部活动'
        }, {
          value: '1',
          label: '校级活动'
        }, {
          value: '2',
          label: '年级活动'
        }, {
          value: '3',
          label: '班级活动'
        }
      ],
      level_type: "-1",
      //全部状态select
      allStatusOptions: [
        {
          value: "-1",
          label: '全部状态'
        }, {
          value: '1',
          label: '报名中'
        }, {
          value: '2',
          label: '进行中'
        }, {
          value: '3',
          label: '已结束'
        }, {
          value: '4',
          label: '已通过'
        }, {
          value: '5',
          label: '未审核'
        }, {
          value: '6',
          label: '已拒绝'
        },
      ],
      status: "-1",
      order_type: "DESC",//DESC：倒序；ASC：升序
      // 分页：
      page_index: 1,
      page_size: 6,
      total_number: 0,
    };
  },
  created() {
    this.getList();
  },
  watch: {

  },
  mounted() {
  },
  computed: {

  },
  methods: {
    // 获取活动数据
    getList() {
      let success = data => {
        this.listData = data.data.data;
        this.total_number = data.data.data_sum;
      };
      this.$ajax({
        url: "api/competition/activity",
        method: "get",
        params: {
          page_index: this.page_index,
          page_size: this.page_size,
          select_type: this.select_type,
          order: this.order,
          user_id: this.userId,
          level_type: this.level_type,
          status: this.status,
          order_type: this.order_type
        },
        func: {
          success: success
        }
      });
    },

    // yyyy-mm-dd hh:mm:ss转成毫秒数
    changeIntoS(timeparma) {
      let theTime = timeparma.replace(new RegExp("-", "gm"), "/");
      let result = new Date(theTime).getTime();
      return result;
    },
    // 分页：
    change_page(val) {
      this.page_index = val;
      this.getList();
    },
    // 点击自己创建的活动：
    delActivity(item) {
      this.$confirm("删除后不可恢复，确定要删除吗？", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        customClass: "removeing"
      })
        .then(() => {
          let success = res => {
            this.$message.success(res.msg);
            this.getList();
          };
          this.$ajax({
            url: "api/competition/activity",
            method: "delete",
            params: {
              id: item.id,
              type: this.select_type,//	1：只删除参与活动的相关记录(我参与的)；2：删除整个活动(我发起的)；
              user_id: this.userId
            },
            func: { success: success }
          });
        })
        .catch(() => { });
    },
    // 编辑未审核的活动
    editActivity(item) {
      this.$router.push({ path: '/events/initiate', query: { id: item.id }});
     },
  }
};
</script>
<style lang="scss">
.school-events{
  .search-bar {
    .el-radio-group {
      height: 60px;
      line-height: 70px;
      .el-radio__input {
        display: none;
      }
      .el-radio__label {
        font-size: 14px;
      }
    }
    .el-icon-sort-down {
      transform: rotateY(180deg);
    }
    .initiate-btn {
      width: 96px;
      height: 40px;
      padding: 0;
      margin-top: 10px;
    }
    .select-tools {
      .el-select {
        width: 200px;
        margin-left: 20px;
        .el-input__inner {
          height: 32px;
          line-height: 32px;
        }
        .el-input__icon {
          line-height: 32px;
        }
      }
    }
  }
  .activities-container {
    .el-radio-group {
      height: 32px;
      line-height: 32px;
    }
    .activities-content {
      margin-top: 20px;
    }
  }
  .tips1 {
    background: url("../../../assets/images/events/pleaceholder (1).png")
      no-repeat center #fff;
  }
  .tips2 {
    background: url("../../../assets/images/events/pleaceholder (5).png")
      no-repeat center #fff;
  }
  .review-status{
      padding: 15px 20px;
      }
}
</style>

